{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37764bitd2lconda94fc7ab78ae34cabbef0e75f5636f253",
   "display_name": "Python 3.7.7 64-bit ('d2l': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Help on built-in function matmul:\n\nmatmul(...)\n    matmul(input, other, out=None) -> Tensor\n    \n    Matrix product of two tensors.\n    \n    The behavior depends on the dimensionality of the tensors as follows:\n    \n    - If both tensors are 1-dimensional, the dot product (scalar) is returned.\n    - If both arguments are 2-dimensional, the matrix-matrix product is returned.\n    - If the first argument is 1-dimensional and the second argument is 2-dimensional,\n      a 1 is prepended to its dimension for the purpose of the matrix multiply.\n      After the matrix multiply, the prepended dimension is removed.\n    - If the first argument is 2-dimensional and the second argument is 1-dimensional,\n      the matrix-vector product is returned.\n    - If both arguments are at least 1-dimensional and at least one argument is\n      N-dimensional (where N > 2), then a batched matrix multiply is returned.  If the first\n      argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the\n      batched matrix multiply and removed after.  If the second argument is 1-dimensional, a\n      1 is appended to its dimension for the purpose of the batched matrix multiple and removed after.\n      The non-matrix (i.e. batch) dimensions are :ref:`broadcasted <broadcasting-semantics>` (and thus\n      must be broadcastable).  For example, if :attr:`input` is a\n      :math:`(j \\times 1 \\times n \\times m)` tensor and :attr:`other` is a :math:`(k \\times m \\times p)`\n      tensor, :attr:`out` will be an :math:`(j \\times k \\times n \\times p)` tensor.\n    \n    .. note::\n    \n        The 1-dimensional dot product version of this function does not support an :attr:`out` parameter.\n    \n    Arguments:\n        input (Tensor): the first tensor to be multiplied\n        other (Tensor): the second tensor to be multiplied\n        out (Tensor, optional): the output tensor.\n    \n    Example::\n    \n        >>> # vector x vector\n        >>> tensor1 = torch.randn(3)\n        >>> tensor2 = torch.randn(3)\n        >>> torch.matmul(tensor1, tensor2).size()\n        torch.Size([])\n        >>> # matrix x vector\n        >>> tensor1 = torch.randn(3, 4)\n        >>> tensor2 = torch.randn(4)\n        >>> torch.matmul(tensor1, tensor2).size()\n        torch.Size([3])\n        >>> # batched matrix x broadcasted vector\n        >>> tensor1 = torch.randn(10, 3, 4)\n        >>> tensor2 = torch.randn(4)\n        >>> torch.matmul(tensor1, tensor2).size()\n        torch.Size([10, 3])\n        >>> # batched matrix x batched matrix\n        >>> tensor1 = torch.randn(10, 3, 4)\n        >>> tensor2 = torch.randn(10, 4, 5)\n        >>> torch.matmul(tensor1, tensor2).size()\n        torch.Size([10, 3, 5])\n        >>> # batched matrix x broadcasted matrix\n        >>> tensor1 = torch.randn(10, 3, 4)\n        >>> tensor2 = torch.randn(4, 5)\n        >>> torch.matmul(tensor1, tensor2).size()\n        torch.Size([10, 3, 5])\n\n"
    }
   ],
   "source": [
    "import torch\n",
    "help(torch.matmul)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Help on built-in function mm:\n\nmm(...)\n    mm(input, mat2, out=None) -> Tensor\n    \n    Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.\n    \n    If :attr:`input` is a :math:`(n \\times m)` tensor, :attr:`mat2` is a\n    :math:`(m \\times p)` tensor, :attr:`out` will be a :math:`(n \\times p)` tensor.\n    \n    .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.\n              For broadcasting matrix products, see :func:`torch.matmul`.\n    \n    Args:\n        input (Tensor): the first matrix to be multiplied\n        mat2 (Tensor): the second matrix to be multiplied\n        out (Tensor, optional): the output tensor.\n    \n    Example::\n    \n        >>> mat1 = torch.randn(2, 3)\n        >>> mat2 = torch.randn(3, 3)\n        >>> torch.mm(mat1, mat2)\n        tensor([[ 0.4851,  0.5037, -0.3633],\n                [-0.0760, -3.6705,  2.4784]])\n\n"
    }
   ],
   "source": [
    "help(torch.mm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "tensor([[ 3.4238, -0.7099, -0.0411],\n        [-2.1631,  0.2358, -0.4109]])"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "mat1 = torch.randn(2, 3)\n",
    "mat2 = torch.randn(3, 3)\n",
    "torch.mm(mat1, mat2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor([[ 3.4238, -0.7099, -0.0411],\n        [-2.1631,  0.2358, -0.4109]])\n"
    }
   ],
   "source": [
    "y1 = mat1 @ mat2\n",
    "print(y1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor(-1.0107)\n"
    }
   ],
   "source": [
    "# vector x vector\n",
    "tensor1 = torch.randn(3)\n",
    "tensor2 = torch.randn(3)\n",
    "y2 = torch.matmul(tensor1, tensor2)\n",
    "print(y2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor(-1.0107)\n"
    }
   ],
   "source": [
    "y2 = tensor1 @ tensor2\n",
    "print(y2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor([ 1.0449,  4.2152, -0.6498])\n"
    }
   ],
   "source": [
    "# matrix x vector\n",
    "tensor1 = torch.randn(3, 4)\n",
    "tensor2 = torch.randn(4)\n",
    "y2 = torch.matmul(tensor1, tensor2)\n",
    "print(y2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor([ 1.0449,  4.2152, -0.6498])\n"
    }
   ],
   "source": [
    "y2 = tensor1 @ tensor2\n",
    "print(y2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor([[ 3.6793, -1.6694,  5.2411],\n        [ 0.3145, -2.3147,  0.4619],\n        [ 2.0606,  2.3739, -0.3811],\n        [ 2.6319,  3.9971,  2.2666],\n        [-0.4953,  4.9969, -1.3417],\n        [-0.3044, -0.1517, -2.7701],\n        [ 2.6207,  0.8561, -1.7904],\n        [-0.0408,  5.2491,  4.1075],\n        [ 4.2419,  1.0194, -1.9672],\n        [ 0.6643,  3.8116, -0.4392]])\ntensor([[ 3.6793, -1.6694,  5.2411],\n        [ 0.3145, -2.3147,  0.4619],\n        [ 2.0606,  2.3739, -0.3811],\n        [ 2.6319,  3.9971,  2.2666],\n        [-0.4953,  4.9969, -1.3417],\n        [-0.3044, -0.1517, -2.7701],\n        [ 2.6207,  0.8561, -1.7904],\n        [-0.0408,  5.2491,  4.1075],\n        [ 4.2419,  1.0194, -1.9672],\n        [ 0.6643,  3.8116, -0.4392]])\n"
    }
   ],
   "source": [
    "# batched matrix x broadcasted vector\n",
    "tensor1 = torch.randn(10, 3, 4)\n",
    "tensor2 = torch.randn(4)\n",
    "y2 = torch.matmul(tensor1, tensor2)\n",
    "print(y2)\n",
    "y3 = tensor1 @ tensor2\n",
    "print(y3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor([[[ 3.5962e-01, -2.0503e+00, -2.3531e+00,  1.2875e+00,  4.3821e+00],\n         [ 8.2339e-01,  5.1257e-01,  2.9941e-01,  5.1188e-03, -1.9942e+00],\n         [-1.4253e+00,  5.7442e-01,  9.8444e-01, -1.2319e+00,  2.3602e-01]],\n\n        [[-1.1798e+00,  1.1250e+00,  3.9087e+00, -2.3977e+00,  2.1217e-01],\n         [ 2.1731e+00, -3.5724e+00,  8.8057e-01,  8.3499e-01,  2.0427e+00],\n         [ 1.4532e-01, -1.5656e+00,  4.0480e+00, -9.8325e-01,  5.2325e-01]],\n\n        [[-2.9855e+00, -1.3098e+00,  2.9881e-02,  3.4328e-01,  1.3893e+00],\n         [ 1.4854e+00, -9.8589e-01, -7.3749e-01,  2.0500e+00, -5.6124e-01],\n         [-9.3872e-01,  1.9814e+00,  2.1519e+00,  8.0297e-01, -3.3341e+00]],\n\n        [[-1.8586e-01, -4.2434e-02, -7.3579e-01,  2.1307e-01, -2.1348e+00],\n         [-1.2433e+00,  1.1012e+00,  4.7378e-01,  1.0749e+00,  2.1763e+00],\n         [ 5.1319e-01, -8.9416e-01, -3.3311e-01, -7.1811e-01, -5.0738e-02]],\n\n        [[-3.6705e-01,  1.6740e+00, -5.9328e-01,  4.3646e-01,  1.2915e+00],\n         [-2.0060e+00,  9.0388e-01, -3.3883e+00,  1.4132e+00, -7.2744e-01],\n         [-5.9376e-01,  3.9724e-01,  2.8649e-01, -9.5285e-01, -8.1128e-01]],\n\n        [[-1.4582e-01, -1.6527e-01,  8.8107e-01,  1.6596e+00, -2.0887e-01],\n         [-2.0858e+00, -1.0061e+00, -2.4387e+00, -9.6280e-01, -1.6909e-01],\n         [-8.5242e-01, -8.7766e-02, -2.7763e+00, -2.9488e+00, -7.1617e-01]],\n\n        [[-4.9619e-01,  1.8193e+00,  2.9406e+00,  4.2436e+00,  1.0086e+00],\n         [ 2.0220e+00, -2.6885e+00, -1.1317e+00, -2.6487e+00, -1.2084e+00],\n         [-2.8395e+00, -1.5992e+00, -3.4768e+00, -3.8545e+00,  1.5598e+00]],\n\n        [[-1.5342e+00, -1.0247e+00, -2.4592e+00, -1.7070e+00,  6.9604e-01],\n         [ 8.7758e-01,  2.0922e+00,  2.4243e+00,  5.2822e+00,  1.7469e-01],\n         [-1.4105e+00, -1.6153e+00, -2.2944e+00, -2.1367e+00,  5.5240e-01]],\n\n        [[-4.6107e+00,  1.9242e+00, -1.8354e+00, -1.5637e+00,  4.0678e-01],\n         [ 7.6749e-01,  2.2113e+00,  1.0515e+00, -3.7026e-01,  1.1757e+00],\n         [-4.6681e-01,  1.2767e+00,  1.1674e-01,  1.0781e+00,  1.7051e+00]],\n\n        [[-6.2175e-01, -8.4118e-01,  1.1722e+00,  5.9796e-01, -4.0566e-01],\n         [-3.0842e+00, -2.1864e+00,  3.8500e+00,  4.1044e+00, -2.3498e-01],\n         [ 2.6657e-01, -2.9716e+00,  2.1631e+00, -1.9393e+00,  1.2943e+00]]])\ntensor([[[ 3.5962e-01, -2.0503e+00, -2.3531e+00,  1.2875e+00,  4.3821e+00],\n         [ 8.2339e-01,  5.1257e-01,  2.9941e-01,  5.1188e-03, -1.9942e+00],\n         [-1.4253e+00,  5.7442e-01,  9.8444e-01, -1.2319e+00,  2.3602e-01]],\n\n        [[-1.1798e+00,  1.1250e+00,  3.9087e+00, -2.3977e+00,  2.1217e-01],\n         [ 2.1731e+00, -3.5724e+00,  8.8057e-01,  8.3499e-01,  2.0427e+00],\n         [ 1.4532e-01, -1.5656e+00,  4.0480e+00, -9.8325e-01,  5.2325e-01]],\n\n        [[-2.9855e+00, -1.3098e+00,  2.9881e-02,  3.4328e-01,  1.3893e+00],\n         [ 1.4854e+00, -9.8589e-01, -7.3749e-01,  2.0500e+00, -5.6124e-01],\n         [-9.3872e-01,  1.9814e+00,  2.1519e+00,  8.0297e-01, -3.3341e+00]],\n\n        [[-1.8586e-01, -4.2434e-02, -7.3579e-01,  2.1307e-01, -2.1348e+00],\n         [-1.2433e+00,  1.1012e+00,  4.7378e-01,  1.0749e+00,  2.1763e+00],\n         [ 5.1319e-01, -8.9416e-01, -3.3311e-01, -7.1811e-01, -5.0738e-02]],\n\n        [[-3.6705e-01,  1.6740e+00, -5.9328e-01,  4.3646e-01,  1.2915e+00],\n         [-2.0060e+00,  9.0388e-01, -3.3883e+00,  1.4132e+00, -7.2744e-01],\n         [-5.9376e-01,  3.9724e-01,  2.8649e-01, -9.5285e-01, -8.1128e-01]],\n\n        [[-1.4582e-01, -1.6527e-01,  8.8107e-01,  1.6596e+00, -2.0887e-01],\n         [-2.0858e+00, -1.0061e+00, -2.4387e+00, -9.6280e-01, -1.6909e-01],\n         [-8.5242e-01, -8.7766e-02, -2.7763e+00, -2.9488e+00, -7.1617e-01]],\n\n        [[-4.9619e-01,  1.8193e+00,  2.9406e+00,  4.2436e+00,  1.0086e+00],\n         [ 2.0220e+00, -2.6885e+00, -1.1317e+00, -2.6487e+00, -1.2084e+00],\n         [-2.8395e+00, -1.5992e+00, -3.4768e+00, -3.8545e+00,  1.5598e+00]],\n\n        [[-1.5342e+00, -1.0247e+00, -2.4592e+00, -1.7070e+00,  6.9604e-01],\n         [ 8.7758e-01,  2.0922e+00,  2.4243e+00,  5.2822e+00,  1.7469e-01],\n         [-1.4105e+00, -1.6153e+00, -2.2944e+00, -2.1367e+00,  5.5240e-01]],\n\n        [[-4.6107e+00,  1.9242e+00, -1.8354e+00, -1.5637e+00,  4.0678e-01],\n         [ 7.6749e-01,  2.2113e+00,  1.0515e+00, -3.7026e-01,  1.1757e+00],\n         [-4.6681e-01,  1.2767e+00,  1.1674e-01,  1.0781e+00,  1.7051e+00]],\n\n        [[-6.2175e-01, -8.4118e-01,  1.1722e+00,  5.9796e-01, -4.0566e-01],\n         [-3.0842e+00, -2.1864e+00,  3.8500e+00,  4.1044e+00, -2.3498e-01],\n         [ 2.6657e-01, -2.9716e+00,  2.1631e+00, -1.9393e+00,  1.2943e+00]]])\n"
    }
   ],
   "source": [
    "# batched matrix x batched matrix\n",
    "tensor1 = torch.randn(10, 3, 4)\n",
    "tensor2 = torch.randn(10, 4, 5)\n",
    "y2 = torch.matmul(tensor1, tensor2)\n",
    "print(y2)\n",
    "y3 = tensor1 @ tensor2\n",
    "print(y3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "tensor([[[ 4.5240e-02, -4.8131e-01,  4.0846e+00,  8.8679e-01,  1.7360e+00],\n         [-1.2648e+00, -1.3842e+00,  4.9948e+00,  3.9899e-01, -2.8527e-01],\n         [ 3.4310e-02,  4.3587e-02, -1.9942e+00, -7.8201e-02, -1.2242e+00]],\n\n        [[ 3.3641e-01, -1.4323e+00,  2.0350e+00,  4.7403e-01,  2.1864e+00],\n         [ 2.1022e+00, -1.3507e+00,  2.7783e+00,  1.3860e+00,  6.3256e+00],\n         [ 6.7521e-02,  1.4192e+00, -5.2495e+00, -7.7951e-01, -2.7875e+00]],\n\n        [[ 6.6205e-01,  3.6713e-01, -4.2775e+00, -9.0613e-01,  2.8942e-01],\n         [-7.2719e-01, -1.2233e+00, -4.8015e-01, -2.5042e+00,  2.3121e+00],\n         [-2.4756e-01,  4.2519e-01, -1.1989e+00, -5.1880e-01, -8.6003e-01]],\n\n        [[ 5.4363e-01, -6.9925e-03,  6.6723e-01,  2.2373e-01,  1.7030e+00],\n         [ 1.1116e+00, -6.0456e-01,  2.6198e-01,  1.3279e+00,  1.3964e+00],\n         [ 1.1348e+00,  6.3887e-01,  1.8070e+00,  2.4552e+00,  1.5859e-01]],\n\n        [[-8.7487e-01, -3.4963e-01,  1.9606e+00, -2.5531e+00,  3.3989e+00],\n         [ 6.6839e-01, -1.7456e+00,  2.6353e+00,  1.1041e-01,  4.3508e+00],\n         [-8.4904e-01, -2.7063e-01, -1.4995e+00, -1.2071e+00, -1.3966e+00]],\n\n        [[ 2.9797e-01, -1.6255e+00,  2.9588e+00,  6.5128e-01,  2.5076e+00],\n         [ 1.2531e+00,  5.1071e-02,  2.0600e+00,  2.4632e+00,  8.9956e-01],\n         [-1.4478e-01, -2.0836e-01, -1.0032e+00, -1.0302e+00,  7.1200e-01]],\n\n        [[ 6.1181e-01, -5.3865e-01, -1.8091e+00, -2.9276e-01,  1.2074e+00],\n         [-1.8959e+00,  4.3999e-02, -1.7802e+00, -2.8707e+00, -1.9238e+00],\n         [ 1.8645e-01, -9.6097e-01,  3.0854e+00,  2.1338e+00, -5.5336e-01]],\n\n        [[ 2.4120e-01,  1.5607e-01,  1.8063e+00,  2.3002e+00, -2.0291e+00],\n         [ 7.3151e-01,  3.0013e-01,  7.4857e-01,  2.3765e+00, -1.5344e+00],\n         [-4.9997e-02,  4.3574e-01, -6.6895e-01, -4.6202e-01,  4.7088e-03]],\n\n        [[-5.2855e-01, -3.8655e-01,  3.5353e-01, -5.8149e-01, -1.4955e-01],\n         [ 2.0258e+00, -7.6212e-01,  3.8120e+00,  3.5585e+00,  2.8571e+00],\n         [-1.9492e+00, -3.7726e-01, -1.4596e+00, -4.3905e+00,  9.4735e-01]],\n\n        [[ 6.5876e-01, -1.9521e-01, -2.3290e-01,  2.7753e-01,  1.3686e+00],\n         [-1.5198e+00, -6.6718e-01, -1.3685e+00, -2.4355e+00, -1.0013e+00],\n         [-7.5047e-01,  1.1799e+00,  5.3345e-01, -6.8731e-02, -2.1560e+00]]])\ntensor([[[ 4.5240e-02, -4.8131e-01,  4.0846e+00,  8.8679e-01,  1.7360e+00],\n         [-1.2648e+00, -1.3842e+00,  4.9948e+00,  3.9899e-01, -2.8527e-01],\n         [ 3.4310e-02,  4.3587e-02, -1.9942e+00, -7.8201e-02, -1.2242e+00]],\n\n        [[ 3.3641e-01, -1.4323e+00,  2.0350e+00,  4.7403e-01,  2.1864e+00],\n         [ 2.1022e+00, -1.3507e+00,  2.7783e+00,  1.3860e+00,  6.3256e+00],\n         [ 6.7521e-02,  1.4192e+00, -5.2495e+00, -7.7951e-01, -2.7875e+00]],\n\n        [[ 6.6205e-01,  3.6713e-01, -4.2775e+00, -9.0613e-01,  2.8942e-01],\n         [-7.2719e-01, -1.2233e+00, -4.8015e-01, -2.5042e+00,  2.3121e+00],\n         [-2.4756e-01,  4.2519e-01, -1.1989e+00, -5.1880e-01, -8.6003e-01]],\n\n        [[ 5.4363e-01, -6.9925e-03,  6.6723e-01,  2.2373e-01,  1.7030e+00],\n         [ 1.1116e+00, -6.0456e-01,  2.6198e-01,  1.3279e+00,  1.3964e+00],\n         [ 1.1348e+00,  6.3887e-01,  1.8070e+00,  2.4552e+00,  1.5859e-01]],\n\n        [[-8.7487e-01, -3.4963e-01,  1.9606e+00, -2.5531e+00,  3.3989e+00],\n         [ 6.6839e-01, -1.7456e+00,  2.6353e+00,  1.1041e-01,  4.3508e+00],\n         [-8.4904e-01, -2.7063e-01, -1.4995e+00, -1.2071e+00, -1.3966e+00]],\n\n        [[ 2.9797e-01, -1.6255e+00,  2.9588e+00,  6.5128e-01,  2.5076e+00],\n         [ 1.2531e+00,  5.1071e-02,  2.0600e+00,  2.4632e+00,  8.9956e-01],\n         [-1.4478e-01, -2.0836e-01, -1.0032e+00, -1.0302e+00,  7.1200e-01]],\n\n        [[ 6.1181e-01, -5.3865e-01, -1.8091e+00, -2.9276e-01,  1.2074e+00],\n         [-1.8959e+00,  4.3999e-02, -1.7802e+00, -2.8707e+00, -1.9238e+00],\n         [ 1.8645e-01, -9.6097e-01,  3.0854e+00,  2.1338e+00, -5.5336e-01]],\n\n        [[ 2.4120e-01,  1.5607e-01,  1.8063e+00,  2.3002e+00, -2.0291e+00],\n         [ 7.3151e-01,  3.0013e-01,  7.4857e-01,  2.3765e+00, -1.5344e+00],\n         [-4.9997e-02,  4.3574e-01, -6.6895e-01, -4.6202e-01,  4.7088e-03]],\n\n        [[-5.2855e-01, -3.8655e-01,  3.5353e-01, -5.8149e-01, -1.4955e-01],\n         [ 2.0258e+00, -7.6212e-01,  3.8120e+00,  3.5585e+00,  2.8571e+00],\n         [-1.9492e+00, -3.7726e-01, -1.4596e+00, -4.3905e+00,  9.4735e-01]],\n\n        [[ 6.5876e-01, -1.9521e-01, -2.3290e-01,  2.7753e-01,  1.3686e+00],\n         [-1.5198e+00, -6.6718e-01, -1.3685e+00, -2.4355e+00, -1.0013e+00],\n         [-7.5047e-01,  1.1799e+00,  5.3345e-01, -6.8731e-02, -2.1560e+00]]])\n"
    }
   ],
   "source": [
    "# batched matrix x broadcasted matrix\n",
    "tensor1 = torch.randn(10, 3, 4)\n",
    "tensor2 = torch.randn(4, 5)\n",
    "y2 = torch.matmul(tensor1, tensor2)\n",
    "print(y2)\n",
    "y3 = tensor1 @ tensor2\n",
    "print(y3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}